package proxyTest.cglib;

import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * @author zyc
 * @create 2022--05--06 16:22
 */
public class StuMethodInterceptor implements MethodInterceptor {
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        System.out.println("拦截到");
        if (method.getName().equals("play")) {
            return methodProxy.invokeSuper(o, objects) + "【真棒】";
        } else if (method.getName().equals("sing")) {
            return method.invoke(o, objects) + "[真好听]";
        } else {
            return methodProxy.invokeSuper(o, objects);
        }
    }
}
